package wuke.dao.imp;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import wuke.dao.XsDao;
import wuke.model.Xsb;
import wuke.utils.HibernateSessionFactory;

public class XsDaoImp implements XsDao{

	public Xsb getOneXs(String xh) {
		
		try {
			Session session = HibernateSessionFactory.getSession();
			Transaction ts = session.beginTransaction();
			
			Query query = session.createQuery("from Xsb where xh=?");
			query.setParameter(0, xh);
			query.setMaxResults(1);
			
			Xsb xs = (Xsb) query.uniqueResult();
			ts.commit();
			session.clear();
			
			return xs;
		} catch (HibernateException e) {
			e.printStackTrace();
			return null;
			
		}
		
	}

	public void update(Xsb xs) {
		
		try {
			Session session = HibernateSessionFactory.getSession();
			Transaction ts = session.beginTransaction();
			
			session.update(xs);
			ts.commit();
			HibernateSessionFactory.closeSession();
		} catch (HibernateException e) {
			e.printStackTrace();
		}
	}
	
}
